package com.showcai.tools;

import com.showcai.log.LogFactory;
import com.showcai.myRunTime.MyRunTimeExcption;
import com.showcai.util.PropertyUtils;
import com.showcai.util.SHA256Tools;
import org.apache.log4j.Logger;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Baggio on 2018-9-14.
 */
public class PushTools {
    public static Logger logger = LogFactory.getLogger(HttpClientHelper.class);
    /**
     * 调用手表厂家接口
     */
    private static final String CHANNEL_ID = "10016";
    private static final String CHANNEL_SECRET = "Sh85ZTJkzQyt1hrq1lEtjIfAaR7DNzS";

    /*push内容到手表*/
    public static void push2DevicService(String devicId, String body) {
        String devicUrl = PropertyUtils.getValue("devic.url") + devicId;
        logger.info(devicUrl);
        logger.info(body);

        Map<String, String> headMap = new HashMap<>();
        headMap.put("Accept", "application/json");
        String timestamp = String.valueOf(System.currentTimeMillis());
        headMap.put("channel_id", CHANNEL_ID);
        headMap.put("timestamp", timestamp);
        String sign = CHANNEL_ID + CHANNEL_SECRET + timestamp;
        headMap.put("sign", SHA256Tools.getSHA256Str(sign));
        headMap.put("Content-Type", "application/json;charset=utf-8");
        try {
            String resStr = HttpClientHelper.postJson(devicUrl, body.trim(), headMap);

        } catch (Exception e) {
            throw new MyRunTimeExcption(e.getMessage());
        }
    }
}
